package bai1;

import java.io.*;
import java.net.*;

//author Mrs. Truong Thi NgoC Anh

public class Client {

	public static void main(String[] args) {
		
		try {
			
			Socket s = new Socket("127.0.0.1",7);
			System.out.println("client da ket noi");
			
			DataOutputStream os = new DataOutputStream(s.getOutputStream());
			BufferedReader ipstr = new BufferedReader(new InputStreamReader(s.getInputStream()));
			InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(isr);
			
			while(true){
				System.out.println();
				System.out.println("Nhap vao mot so - Nhap -1 de thoat");
				String str = br.readLine();
				os.writeBytes(str);
				os.write(13);
				os.write(10);
				os.flush();
				str = ipstr.readLine();
				System.out.println(str);
				if(str.equals("quit")) break;
			}
			System.out.println();
			System.out.println("Client ngat ket noi");
			s.close();
		} catch (IOException e) {
			System.out.println("Loi: khong tao duoc socket");
		}
		
	}
}
